import Cookies from 'js-cookie'

const cookieId = "JSESSIONID"
const user = {
    state: {
        id: 1,
        username:"",
        hasShop:false,
        token: Cookies.get(cookieId) // 获取名为 JSESSIONID 的 cookie 数据 作为token使用
    },
    getters: {
        //获取id
        getId(state) {
            console.log("getId:" + state.id)
            return state.id
        },
        getShop(state) {
            return state.hasShop
        },
        getToken(state) {
            return state.token
        },
        getUserName(state){
            return state.username
        }
    },
    mutations: {
        //保存id
        saveId(state, id) {
            state.id = id
        },
        saveUsernameAndId(state, user) {
            //console.log("user")
            //console.log(user)
            console.log(user);

            state.id = user.id
            if(user.status<=0){
                state.hasShop=false;
            }else{
                state.hasShop=true;
            }
            console.log("登录判断是否有店")
            console.log(state.hasShop)
            state.username=user.sellerName
        },
        saveToken(state) {
            state.token = Cookies.get(cookieId)
        },
        removeToken(state) {
            state.token = ''
        }
    },
    actions: {}
}
export default user
